/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.bjj.ui.component;

import com.bff.mpd.musicjukebox.lib.ColorProperties;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JList;

/**
 *
 * @author Bill
 */
public class MusicList extends JList {

    /** Creates a new instance of SongList */
    public MusicList() {
        super();
    }

    public MusicList(Object[] listData) {
        super(listData);
    }

    public MusicList(Vector listData) {
        super(listData);
    }

    public MusicList(DefaultListModel model) {
        super(model);
    }

    /**
     * Paints empty rows too, after letting the UI delegate do
     * its painting.
     */
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        paintEmptyRows(g);
    }

    /**
     * Paints the backgrounds of the implied empty rows when the
     * table model is insufficient to fill all the visible area
     * available to us. We don't involve cell renderers, because
     * we have no data.
     */
    protected void paintEmptyRows(Graphics g) {
        try {
            final Rectangle clip = g.getClipBounds();
            double rowHeight = getCellBounds(0, 0).getHeight();
            int rowCount = getModel().getSize();

            if (rowCount * rowHeight < clip.height) {
                for (int i = rowCount; i <= clip.height / rowHeight; ++i) {
                    g.setColor(colorForRow(i));
                    g.fillRect(clip.x, (int) (i * rowHeight), clip.width, (int) rowHeight);
                }
            }
        } catch (Exception e) {
        }
    }
    
    /**
     * Returns the appropriate background color for the given row.
     */
    protected Color colorForRow(int row) {
        return (row % 2 == 0) ? ColorProperties.LIST_BACKGROUND_EVEN : ColorProperties.LIST_BACKGROUND_ODD;
    }
}
